package com.deYang.app.ljodfh.ui.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.deYang.app.ljodfh.R;
import com.deYang.app.ljodfh.ui.fragment.ProgramBackFragment;
import com.deYang.app.ljodfh.ui.fragment.TvLivingFragment;

/**
 * Created by Administrator on 2017/7/13 0013.
 */

public class TvAdapter extends FragmentPagerAdapter {
    private TvLivingFragment tvLivingFragment;
    private ProgramBackFragment programBackFragment;
    private String[] titles;

    private boolean isParentShowing;


    public TvAdapter(FragmentManager fm, Context context) {
        super(fm);
        titles = new String[]{context.getString(R.string.tv_living)};
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            if (tvLivingFragment == null) {
                tvLivingFragment = new TvLivingFragment();
                tvLivingFragment.setParentShowing(isParentShowing);
            }
            tvLivingFragment.setIndexInViewPager(position);
            return tvLivingFragment;
        } else {
            if (programBackFragment == null) {
                programBackFragment = new ProgramBackFragment();
                programBackFragment.setParentShowing(isParentShowing);
            }
            programBackFragment.setIndexInViewPager(position);
            return programBackFragment;
        }
    }

    @Override
    public int getCount() {
        return 1;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        //  return super.getPageTitle(position);
        return titles[position];
    }

    public void setParentShowing(boolean parentShowing) {
        isParentShowing = parentShowing;
        if (tvLivingFragment != null) {
            tvLivingFragment.setParentShowing(isParentShowing);
        }
        if (programBackFragment != null) {
            programBackFragment.setParentShowing(isParentShowing);
        }
    }

    public ProgramBackFragment getProgramBackFragment() {
        return programBackFragment;
    }

    public TvLivingFragment getTvLivingFragment() {
        return tvLivingFragment;
    }
}
